﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Max.Ph5_2009A.NewShopping.IService
{
    public interface IBaseService<T> where T : class,new()
    {
        #region 同步方法

        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns>受影响行数</returns>
        int Insert(T t);

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns>受影响行数</returns>
        int Update(T t);

        /// <summary>
        /// 删除数据（单删除和批量删除）
        /// </summary>
        /// <param name="ts"></param>
        /// <returns>受影响行数</returns>
        int Delete(List<T> ts);

        /// <summary>
        /// 查询所有数据
        /// </summary>
        /// <returns>数据集</returns>
        IQueryable<T> Select();

        /// <summary>
        /// 查询分页数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        IQueryable<T> Select(int pageIndex,int pageSize, out int total);

        /// <summary>
        /// 根据条件查询分页数据
        /// </summary>
        /// <param name="where"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        IQueryable<T> Select(System.Linq.Expressions.Expression<Func<T,bool>> where,int pageIndex,int pageSize, out int total);

        /// <summary>
        /// 根据条件查询并排序分页数据
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="where"></param>
        /// <param name="sort"></param>
        /// <param name="IsAsc"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        IQueryable<T> Select<TKey>(System.Linq.Expressions.Expression<Func<T, bool>> where, 
            System.Linq.Expressions.Expression<Func<T,TKey>> sort ,bool IsAsc,
            int pageIndex, int pageSize, out int total);

        #endregion
    }
}
